﻿using System;
using System.Collections.Generic;

namespace CSharp进阶_List
{
	abstract class Monster
	{
		public static List<Monster> monsters = new List<Monster>();
		public Monster()
		{
			monsters.Add(this);
		}
		public abstract void Attack();
	}
	class Boss : Monster
	{
		public override void Attack()
		{
			Console.WriteLine("boss 攻击");
		}
	}
	class Goblin : Monster
	{
		public override void Attack()
		{
			Console.WriteLine("goblin 攻击");
		}
	}
	class Program
	{
		static void Main(string[] args)
		{
			Boss b1 = new Boss();
			Boss b2 = new Boss();
			Goblin g1 = new Goblin();
			Goblin g2 = new Goblin();
			foreach(var item in Monster.monsters)
			{
				item.Attack();
			}

			//List<int> l1 = new List<int>();
			//#region 增
			//// 1.单个增
			//l1.Add(10);
			//l1.Add(20);
			//l1.Add(30);
			//// 2.范围增
			//l1.AddRange(l1);
			//// 3.insert
			//l1.Insert(3, 500);
			//#endregion
			//#region 删
			//// 1.通过值
			//l1.Remove(10);
			//// 2.通过下标
			//l1.RemoveAt(0);
			//#endregion
			//#region 查
			//// 1.正向查
			//if (l1.Contains(30))
			//{
			//	Console.WriteLine("存在 30");
			//}
			//else
			//{
			//	Console.WriteLine("不存在 30");
			//}
			//int index = l1.IndexOf(30);
			//if (index != -1)
			//{
			//	Console.WriteLine("30 下标为：" + index);
			//}
			//else
			//{
			//	Console.WriteLine("不存在 30");
			//}
			//// 2.反向查
			//index = -1;
			//index = l1.LastIndexOf(20);
			//if (index != -1)
			//{
			//	Console.WriteLine("20 下标为：" + index);
			//}
			//else
			//{
			//	Console.WriteLine("不存在 20");
			//}
			//#endregion
			//#region 改
			//l1[0] = 100;
			//#endregion
			//#region 遍历
			//Console.WriteLine(l1.Count);
			//Console.WriteLine(l1.Capacity);
			//for (int i = 0; i < l1.Count; i++)
			//{
			//	Console.Write(l1[i] + " ");
			//}
			//Console.WriteLine();
			//Console.WriteLine();

			//foreach (var item in l1)
			//{
			//	Console.Write(item + " ");
			//}
			//Console.WriteLine();
			//Console.WriteLine();
			//#endregion
		}

		static void print<T>(List<T> l1)
		{
			Console.WriteLine(l1.Count);
			Console.WriteLine(l1.Capacity);
			for (int i = 0; i < l1.Count; i++)
			{
				Console.Write(l1[i] + " ");
			}
			Console.WriteLine();
			Console.WriteLine();
		}
	}
}
